package com.lanou.dllo.findfood.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.lanou.dllo.findfood.entity.BookList;
import com.lanou.dllo.findfood.fragment.BookFragment;
import com.lanou.dllo.findfood.util.JazzyViewPager;


import java.util.List;

/**
 * Created by dllo on 15/10/28.
 */
public class BookViewPerAdpter extends FragmentPagerAdapter {

    private List<BookList> listList;
    private JazzyViewPager mJazzy;


    public void   addData(List<BookList> list)
    {
        listList = list;
        notifyDataSetChanged();

    }
    public BookViewPerAdpter(FragmentManager fm,JazzyViewPager mJazzy) {
        super(fm);
        this.mJazzy = mJazzy;
    }




    @Override
    public Fragment getItem(int position) {
        String mages;
        String title;
        int sum;
        BookList list = listList.get(listList.size()-1-position);//取下标值得到集合
        mages = list.getMessage();
        title = list.getTitle();
        sum =listList.size();

        BookFragment bf = BookFragment.getInstance(mages,title,position+1,sum);
        mJazzy.setObjectForPosition(bf,position);//使用翻页动画效果
        return bf;
    }

    public void destroyItem(ViewGroup container, int position, Object obj) {
        container.removeView(mJazzy.findViewFromObject(position));
    }

    @Override
    public int getCount() {
        return listList != null && listList.size()>0? listList.size():0;

    }


}

